pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let num1_str: &str;
    let num2_str: u32;
    let num: u32;

    match num_str.find('(') {
        Some(i) => {
            num1_str = &num_str[..i];
            let num2 = &num_str[i + 1..];
            match num2.find(')') {
                Some(i) => {
                    let num2_s = &num2[..i];
                    num2_str = num2_s.parse().expect("Failed to parse number");

                    match u32::from_str_radix(num1_str, num2_str) {
                        Ok(n) => {
                            num = n;
                        }
                        Err(e) => return e.to_string(),
                    }
                }
                None => {
                    return "Invalid input string".to_string();
                }
            }
        }
        None => return "Invalid input string".to_string(),
    }

    let end = match to_base {
        2 => {
            format!("{:b}", num)
        }
        8 => {
            format!("{:o}", num)
        }
        10 => {
            format!("{}", num)
        }
        16 => {
            format!("{:x}", num)
        }
        _ => {
            if num == 0 {
                return "0".to_string();
            }
            let mut result = String::new();
            let mut value = num;

            while value > 0 {
                let remainder = value % to_base;
                value /= to_base;
                let digit = if remainder < 10 {
                    char::from_digit(remainder, 10).unwrap()
                } else {
                    char::from_digit(remainder - 10, 36).unwrap()
                };

                result.push(digit);
            }
            result = result.chars().rev().collect();

            result
        }
    };

    end
}
